package com.wss.dao;

import com.wss.domain.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 订单dao接口
 */
@Repository
public interface OrderDao {

    /**
     * 查询所有订单
     * @return
     */
    @Select("select orders.*,vtitle,vprice,username from orders inner join video on (orders.v_id = video.id) inner join account on (orders.u_id = account.id) ORDER BY orders.id")
    List<Order> findOrderAll();

    /**
     * 根据用户id查询该用户订单
     * @param uid
     * @return
     */
    @Select("select orders.*,video.vtitle,video.vprice,account.username from orders inner join video on (orders.v_id = video.id and orders.u_id = #{uid}) inner join account on (orders.u_id = account.id) order by orders.id")
    List<Order> findOrderByUid(int uid);

    /**
     * 根据用户id和视频id查询订单
     * @param order
     * @return
     */
    @Select("select * from orders where orders.v_id = #{v_id} and orders.u_id = #{u_id}")
    Order findOrderByUidnVid(Order order);

    /**
     * 添加订单
     * @param order
     * @return
     */
    @Insert("insert into orders (otime,v_id,u_id) values (curdate(),#{v_id},#{u_id})")
    int addOrder(Order order);

    /**
     * 修改订单
     * @param order
     */
    @Update("update orders set v_id=#{v_id},u_id=#{u_id} where id=#{id}")
    void changeOrder(Order order);

    /**
     * 删除订单
     * @param order
     * @return
     */
    @Delete("delete orders from orders where id=#{id}")
    int deleteOrder(Order order);

}
